﻿using System.Collections.Generic;

namespace Edu.Technion.CSE.OpenUnit4.CollectionsLib
{
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class BinTreeNode<T> : ITreeNode<T>
    {
        // Members
        private T info;  /// Holds the information of the node
        private BinTreeNode<T> left; /// Holds reference to the left child
        private BinTreeNode<T> right; /// Holds reference to the left child

        // Constructors

        /// <summary>
        /// Constructor: build a single node, with no child.
        /// </summary>
        /// <param name="info"></param>
        public BinTreeNode(T info)
        {
            this.left = null;
            this.info = info;
            this.right = null;
        }

        /// <summary>
        /// Constructor: Build a node, with left and right children.
        /// </summary>
        /// <param name="left"></param>
        /// <param name="info"></param>
        /// <param name="right"></param>
        public BinTreeNode(BinTreeNode<T> left, T info, BinTreeNode<T> right)
        {
            this.left = left;
            this.info = info;
            this.right = right;
        }

        // Public Methods

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public T GetInfo()
        {
            return info;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public BinTreeNode<T> GetLeft()
        {
            return left;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public BinTreeNode<T> GetRight()
        {
            return right;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="newInfo"></param>
        public void SetInfo(T newInfo)
        {
            info = newInfo;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="newLeft"></param>
        public void SetLeft(BinTreeNode<T> newLeft)
        {
            left = newLeft;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="newRight"></param>
        public void SetRight(BinTreeNode<T> newRight)
        {
            right = newRight;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        /// <remarks>We should think on alternative implementation</remarks>
        public override string ToString()
        {
            return this.info.ToString();
        }
    }
}
